<!--conf
<sample in_favorites="true">
              <product version="1.5" edition="pro"/>
                     <modifications>
                            <modified date="070101"/>
                     </modifications>
               <sampledescription><![CDATA[Grouppng is new functioality for dhtmlxGrid v.1.5. Try it and you'll see how flexible it is and how useful it can be for users of your application.]]></sampledescription></sample>
 --> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Grouping rows by column</title>
	
</head>

<body>
<link rel='STYLESHEET' type='text/css' href='../common/style.css'>
<table cellspacing="0" cellpadding="0" class="sample_header" border="0">
	<tr valign="middle">
		<!-- COMPONENT ICON -->
		<td width="40" align="center"><img src="../common/dhtmlxgrid_icon.gif" border="0"></td>
		<!-- COMPONENT NAME -->
		<td width="150" align="left" nowrap="true">Sample: dhtmlxGrid</td>
		<!-- SAMPLE TITLE -->
		<td width="0" align="left" nowrap><b>Grouping rows by column</b></td>
		<!-- LINK TO COMPONENT PAGE -->
		<td width="0" align="right"><a href="http://www.dhtmlx.com/docs/products/dhtmlxGrid/index.shtml">dhtmlxGrid main page</a></td>
		<!-- CLOSE BUTTON -->
		<td width="50"><div class="sample_close"><a href="javascript:void(0);" onclick="self.close();"><img src="../common/sample_close.gif" width="14" height="14" border="0" alt="X"></a></div></td>
	</tr>
</table>
	
	
	<p>Grid provides grouping rows by column.</p>
	<link rel="STYLESHEET" type="text/css" href="../../codebase/dhtmlxgrid.css">
	<link rel="STYLESHEET" type="text/css" href="../../codebase/dhtmlxgrid_skins.css">
	<script  src="../../codebase/dhtmlxcommon.js"></script>
	<script  src="../../codebase/dhtmlxgrid.js"></script>
	<script  src="../../codebase/dhtmlxgridcell.js"></script>	
<script  src="../../codebase/ext/dhtmlxgrid_splt.js"></script>	
	<script  src="../../codebase/ext/dhtmlxgrid_group.js"></script>	
	
	<table width="600px">
		<tr>
			<td>
				<input type="button" name="a2" value="ungroup" onclick="mygrid.unGroup();">&nbsp;&nbsp;
				<input type="button"  name="q1" value="regroup by" onclick='mygrid.groupBy(document.getElementById("sel").value);'>
				<select id="sel">
					<option value="0">Sales</option><option value="1">Book title</option><option value="2">Author</option><option value="3">Price</option>
					<option value="4">In Store</option><option value="5">Shipping</option><option value="6">Bestseller</option><option value="7">Date of Publication</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>
				<div id="gridbox" width="100%" height="250px" style="background-color:white;"></div>
			</td>
		</tr>
		<tr>
			<td>
				<a href="javascript:void(0)" onclick="if(mygrid._groups['John Grisham']) mygrid.expandGroup('John Grisham'); else alert('There is no such group!');">expand </a>/<a href="javascript:void(0)" onclick="if(mygrid._groups['John Grisham']) mygrid.collapseGroup('John Grisham'); else alert('There is no such group!')"> colapse</a> 'John Grisham'<br/>
				<a href="javascript:void(0)" onclick="mygrid.expandAllGroups()">expand </a>/<a href="javascript:void(0)" onclick="mygrid.collapseAllGroups()"> colapse</a> all groups<br/>
            	<a href="javascript:void(0)" onclick="mygrid.addRow((new Date()).valueOf(),[1,'The King of Torts','John Grisham',3,1,1,1,0],-1)">add </a>/<a href="javascript:void(0)" onclick="if (mygrid.getSelectedId()) mygrid.deleteRow(mygrid.getSelectedId()); else alert('Please, select any row');"> delete selected</a>
			</td>
		</tr>
	</table>

<script>



	mygrid = new dhtmlXGridObject('gridbox');
	mygrid.setImagePath("../../codebase/imgs/");
	mygrid.setHeader("Sales,Book Title,Author,Price,In Store,Shipping,Bestseller,Date of Publication");
	mygrid.setInitWidths("50,150,100,80,80,80,80,200")
	mygrid.setColAlign("right,left,left,right,center,left,center,center")
	mygrid.setColTypes("dyn,edtxt,ed,price,ch,co,ra,ro");
	mygrid.setColSorting("na,str,str,int,int,int,na,na")

	mygrid.init();


	mygrid.groupBy(2);

	mygrid.setSkin("xp")
	mygrid.loadXML("grid.xml");
</script>
	
<div class='sample_code'><div class="hl-main"><pre><span class="hl-code"> 
    
    </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">groupBy</span><span class="hl-brackets">(</span><span class="hl-number">2</span><span class="hl-brackets">)</span><span class="hl-code">;  </span><span class="hl-comment">//</span><span class="hl-comment"> grouping by third column </span><span class="hl-comment"></span><span class="hl-code">
     
    </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">loadXML</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">grid.xml</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    
    </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">unGroup</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;   </span><span class="hl-comment">//</span><span class="hl-comment"> ungroup grid</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">expandGroup</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">John Grisham</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">; 
    </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">collapseGroup</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">John Grisham</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">; 
    </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">expandAllGroups</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;  
    </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">colapseAllGroups</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;</span></pre></div></div>
<!-- FOOTER -->
<table callspacing="0" cellpadding="0" border="0" class="sample_footer"><tr><td style="padding-left: 8px;">&copy; <a href="http://www.dhtmlx.com">DHTMLX LTD</a>. All rights reserved</td></tr></table>
<!-- FOOTER -->

</body>
</html>
